#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
using LL = long long;

const int N = 2e5 + 10;

int n, m;
int q[N];
LL prex[N], rprex[N];   //prex[i] q[i] --> q[i + 1]   rprex[i] q[i] --> q[i - 1]
LL sum[N], rsum[N];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);


    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++){
        scanf("%d", &q[i]);
    }

    for (int i = 1; i + 1 <= n; i ++){
        if(q[i + 1] < q[i]){
            prex[i] = q[i] - q[i + 1];
        }else{
            prex[i] = 0;
        }
    }





    for (int i = n; i - 1 >= 1; i--)
    {
        if (q[i - 1] < q[i])
        {
            rprex[i] = q[i] - q[i - 1];
        }
        else
        {
            rprex[i] = 0;
        }
    }





    for (int i = 1; i + 1 <= n; i++)
    {
        sum[i] = (LL)sum[i - 1] + prex[i];
    }





    for (int i = n; i - 1 >= 1; i --){
        rsum[i] = (LL)rsum[i + 1] + rprex[i];
    }



    int a, b;
    while(m --){
        scanf("%d%d", &a, &b);
        if(a < b){
            LL res = sum[b - 1] - sum[a - 1];
            printf("%lld\n", res);
        }else{
            //
            LL res = rsum[b + 1] - rsum[a + 1];
            printf("%lld\n", res);
        }
    }

    return 0;
}